﻿using System;
using System.Windows;
using Microsoft.Practices.ServiceLocation;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Configuration;

namespace Atha.Clients.Wpf
{
	public partial class App : Application
	{
		private void Application_Startup(object sender, StartupEventArgs e)
		{
			AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

			var unity = new UnityContainer();
			var serviceLocator = new UnityServiceLocator(unity);

			unity.LoadConfiguration();

			ServiceLocator.SetLocatorProvider(() => serviceLocator);
		}

		void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
		{
			if (e.IsTerminating)
				MessageBox.Show("Unexpected error in the application! Terminating now.");
			else
				MessageBox.Show("Unexpected error in the application!");
		}
	}
}